/*
 * Copyright (c) 2025 Li Auto Inc. and its affiliates
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef XMLPARSER_WRITERATTRIBUTES_H_
#define XMLPARSER_WRITERATTRIBUTES_H_

#include <xmlparser/qos/XMLQosPolicies.hpp>
#include <deps/common/Time_t.h>
#include <deps/common/collections/ResourceLimitedContainerConfig.hpp>

#include <functional>
#include <vector>

namespace vbsutil {
namespace xmlparser {

/**
 * Struct WriterTimes, defining the times associated with the Reliable Writers events.
 * @ingroup RTPS_ATTRIBUTES_MODULE
 */
struct WriterTimes {
    //! Initial heartbeat delay. Default value ~11ms.
    Duration_t initialHeartbeatDelay;
    //! Periodic HB period, default value 3s.
    Duration_t heartbeatPeriod;
    //! Delay to apply to the response of a ACKNACK message, default value ~5ms.
    Duration_t nackResponseDelay;
    //! This time allows the RTPSWriter to ignore nack messages too soon after the data as sent,
    //! default value 0s.
    Duration_t nackSupressionDuration;
    //! Fast periodic HB period, default value 3s.
    Duration_t fastHeartbeatPeriod;

    WriterTimes() {
        // initialHeartbeatDelay.fraction = 50*1000*1000;
        initialHeartbeatDelay.nanosec = 12U * 1000U * 1000U;
        heartbeatPeriod.seconds = 3;
        // nackResponseDelay.fraction = 20*1000*1000;
        nackResponseDelay.nanosec = 5 * 1000 * 1000U;
        fastHeartbeatPeriod.seconds = 1;
    }

    virtual ~WriterTimes() {}

    WriterTimes(const WriterTimes&) = default;
    WriterTimes& operator=(const WriterTimes&) = default;
    WriterTimes(WriterTimes&&) noexcept = default;

    WriterTimes& operator=(WriterTimes&& other) noexcept {
        if (this != &other) {
            this->initialHeartbeatDelay = std::move(other.initialHeartbeatDelay);
            this->heartbeatPeriod = std::move(other.heartbeatPeriod);
            this->nackResponseDelay = std::move(other.nackResponseDelay);
            this->nackSupressionDuration = std::move(other.nackSupressionDuration);
            this->fastHeartbeatPeriod = std::move(other.fastHeartbeatPeriod);
        }
        return *this;
    }

    bool operator==(const WriterTimes& b) const {
        return (this->initialHeartbeatDelay == b.initialHeartbeatDelay) &&
               (this->heartbeatPeriod == b.heartbeatPeriod) && (this->nackResponseDelay == b.nackResponseDelay) &&
               (this->nackSupressionDuration == b.nackSupressionDuration) &&
               (this->fastHeartbeatPeriod == b.fastHeartbeatPeriod);
    }
};

}  // namespace xmlparser
}  // namespace vbsutil

#endif /*DSFDDS_WRITERATTRIBUTES_H_ */
